<?php
/********************************
 *                              *
 * 数据库配置文件             *
 *                              *
 * ******************************
 */
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Mvc\Collection\Manager;

// 漫画主库 写
$di->set('dbCartoonMaster', function ()
{
    return new DbAdapter(array(
        "host"     => "192.168.31.178",
        "username" => "fox",
        "password" => "fox",
        "dbname"   => "hm_cartoon",
        "charset"  => 'utf8',
    ));
});

// 漫画主库 读
$di->set('dbCartoonSlave', function ()
{
    return new DbAdapter(array(
        "host"     => "192.168.31.178",
        "username" => "fox",
        "password" => "fox",
        "dbname"   => "hm_cartoon",
        "charset"  => 'utf8',
    ));
});


// 默认  读
$di->setShared('mongo', function () {
    /** @var \Phalcon\DiInterface $this */
    $dsn = 'mongodb://fox:fox@192.168.31.178:27017';
    $mongo = new \Phalcon\Db\Adapter\MongoDB\Client($dsn);

    return $mongo->selectDatabase('icartoon');
});

//写
$di->setShared('mongoSlave', function () {
    /** @var \Phalcon\DiInterface $this */
    $dsn = 'mongodb://fox:fox@192.168.31.178:27017';
    $mongo = new \Phalcon\Db\Adapter\MongoDB\Client($dsn);

    return $mongo->selectDatabase('icartoon');
});

// Collection Manager is required for MongoDB
$di->setShared('collectionManager', function () {
    return new Manager();
});

$di->set('redisUser', function ()
{
    $redis = new \Redis();
    $redis->connect('127.0.0.1', 6379);
    return $redis;
});